//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.apache.dubbo.config.spring.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;

import java.util.Objects;

abstract class OneTimeExecutionApplicationContextEventListener implements ApplicationListener, ApplicationContextAware {
    private ApplicationContext applicationContext;

    OneTimeExecutionApplicationContextEventListener() {
    }

    public final void onApplicationEvent(ApplicationEvent event) {
        if (this.isOriginalEventSource(event) && event instanceof ApplicationContextEvent) {
            this.onApplicationContextEvent((ApplicationContextEvent)event);
        }

    }

    protected abstract void onApplicationContextEvent(ApplicationContextEvent event);

    private boolean isOriginalEventSource(ApplicationEvent event) {
        return this.applicationContext == null || Objects.equals(this.applicationContext, event.getSource());
    }

    public final void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public ApplicationContext getApplicationContext() {
        return this.applicationContext;
    }
}
